package com.twinkle.note.biz.rpc;

import com.twinkle.framework.common.response.Response;
import com.twinkle.user.api.UserFeignApi;
import com.twinkle.user.dto.req.FindUserByIdReqDTO;
import com.twinkle.user.dto.resp.FindUserByIdRspDTO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Component
public class UserRpcService {

    @Resource
    private UserFeignApi  userFeignApi;
    public FindUserByIdRspDTO findById(Long creatorId) {
        FindUserByIdReqDTO findUserByIdReqDTO = new FindUserByIdReqDTO();
        findUserByIdReqDTO.setId(creatorId);

        Response<FindUserByIdRspDTO> response = userFeignApi.findById(findUserByIdReqDTO);
        if (Objects.isNull(response) || !response.isSuccess()) {
            return null;
        }

        return response.getData();
    }
}
